﻿<template>
  <div>
    <el-tabs type="border-card" class="demo-tabs" >
      <div class="stall-container">
    <el-tab-pane label="车位运营">
    <el-card shadow="hover" :body-style="{ paddingBottom: '0' }"> 
      <el-form :model="queryParams" ref="queryForm" labelWidth="90">
        <el-row>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item label="关键字">
              <el-input v-model="queryParams.searchKey" clearable="" placeholder="请输入模糊查询关键字"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="车位号">
              <el-input v-model="queryParams.carNo" clearable="" placeholder="请输入车位号"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="用户电话">
              <el-input v-model="queryParams.occupantPhone" clearable="" placeholder="请输入用户电话"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="用户名字">
              <el-input v-model="queryParams.peopleIdOccupantName" clearable="" placeholder="请输入用户名"/>           
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="运营模式">
              <el-select clearable="" v-model="queryParams.operation" placeholder="请选择运营模式">
                <!-- <el-option v-for="(item,index) in dl('GenderEnum')" :key="index" :value="item.code" :label="`[${item.code}] ${item.value}`" /> -->
                <el-option :value="1" label="销售">销售</el-option>
								<el-option :value="2" label="租赁">租赁</el-option>
								<!-- <el-option :value="3" label="维修中">维修中</el-option>
								<el-option :value="4" label="代售">代售</el-option>
								<el-option :value="5" label="停用">停用</el-option> -->
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item >
              <el-button-group style="display: flex; align-items: center;">
                <el-button type="primary"  icon="ele-Search" @click="handleQuery" v-auth="'stall:page'"> 查询 </el-button>
                      <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
                        <el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!showAdvanceQueryUI" style="margin-left:5px;"> 高级查询 </el-button>
                        <el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="showAdvanceQueryUI" style="margin-left:5px;"> 隐藏 </el-button>
                <el-button type="primary" style="margin-left:5px;" icon="ele-Plus" @click="openAddStall" v-auth="'stall:add'"> 新增 </el-button>
                
              </el-button-group>
            </el-form-item>
            
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card class="full-table" shadow="hover" style="margin-top: 5px" >
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
                				row-key="id"
                @sort-change="sortChange"
				border="">
        <el-table-column type="index" label="序号" width="55" align="center"/>
        <el-table-column prop="carNo" label="车位号"  show-overflow-tooltip="" />
        <el-table-column prop="roomId" label="所属小区"  show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.roomIdCommunityName}}</span>
            
          </template>
          
        </el-table-column>
          <el-table-column prop="carType" label="车位类型"  show-overflow-tooltip="" >
            <template v-slot="scope">
              <el-tag v-if="scope.row.carType==1">地面</el-tag>
              <el-tag v-if="scope.row.carType==2" type="success">地库</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="operation" label="运营模式"  show-overflow-tooltip="" >
            <template v-slot="scope">
              <el-tag v-if="scope.row.operation==1" type="warning">销售</el-tag>
              <el-tag v-if="scope.row.operation==2" type="danger">租赁</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="operationState" label="运营状态" show-overflow-tooltip="" @click="bb">
            <template v-slot="scope">
              <el-tag v-if="scope.row.operationState==1" type="warning">正常</el-tag>
              <el-tag v-if="scope.row.operationState==2" type="danger">待租</el-tag>
              <el-tag v-if="scope.row.operationState==3" type="success">维修中</el-tag>
              <el-tag v-if="scope.row.operationState==4" type="primary">待售</el-tag>
              <el-tag v-if="scope.row.operationState==5" type="info">停用</el-tag>
            </template>   
          </el-table-column>    

            <el-table-column label="用户名" prop="peopleId">
              <template #default="scope">
                <span v-if="scope.row.operationState==1||scope.row.operationState==3||scope.row.operationState==5">{{scope.row.peopleIdOccupantName}}</span>
              <span v-else-if="scope.row.operationState==2||scope.row.operationState==4"></span>
            </template>
            </el-table-column>
            <el-table-column label="用户电话" prop="peopleId">
              <template #default="scope">
                <span v-if="scope.row.operationState==1||scope.row.operationState==3||scope.row.operationState==5">{{scope.row.occupantPhone}}</span>
              <span v-else-if="scope.row.operationState==2||scope.row.operationState==4"></span>
              <!-- <span>{{scope.row.occupantPhone}}</span>         -->
            </template>
            </el-table-column>
            <el-table-column label="审核时间" prop="peopleId" sortable>
              <template #default="scope">
                <span v-if="scope.row.operationState==1||scope.row.operationState==3||scope.row.operationState==5">{{scope.row.peopleIdOccupantTime}}</span>
              <span v-else-if="scope.row.operationState==2||scope.row.operationState==4"></span>
              <!-- <span>{{scope.row.peopleIdOccupantTime}}</span>      -->
            </template>
            </el-table-column>

          <!-- <el-table-column label="用户电话" prop="occupantPhone"></el-table-column> -->
        <el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('stall:update') || auth('stall:delete')">
          <template #default="scope">
          <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditStall(scope.row)" v-auth="'stall:update'"> 编辑 </el-button> 
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delStall(scope.row)" v-auth="'stall:delete'"> 删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

  </el-tab-pane>
    <el-tab-pane label="车位档案">
      <el-card shadow="hover" :body-style="{ paddingBottom: '0' }"> 
      <el-form :model="queryParams" ref="queryForm" labelWidth="90">
        <el-row>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item label="关键字">
              <el-input v-model="queryParams.searchKey" clearable="" placeholder="请输入模糊查询关键字"/>
              
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="车位号">
              <el-input v-model="queryParams.carNo" clearable="" placeholder="请输入车位号"/> 
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="所属小区" prop="carState">
							<el-select clearable v-model="queryParams.roomId" placeholder="请选择所属小区">
								<el-option :value="1" label="A区">A区</el-option>
								<el-option :value="2" label="B区">B区</el-option>
							</el-select>	
						</el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="车位类型">
              <el-select clearable="" v-model="queryParams.carType" placeholder="请选择车位类型">
                <el-option :value="1" label="地面">地面</el-option>
								<el-option :value="2" label="地库">地库</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
            <el-form-item label="运营模式">
              <el-select clearable="" v-model="queryParams.operation" placeholder="请选择运营模式">
                <el-option :value="1" label="销售">销售</el-option>
								<el-option :value="2" label="租赁">租赁</el-option>
              </el-select>
            </el-form-item>
          </el-col>
        
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item >
              <el-button-group style="display: flex; align-items: center;">
                <el-button type="primary"  icon="ele-Search" @click="handleQuery" v-auth="'stall:page'"> 查询 </el-button>
                      <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
                        <el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!showAdvanceQueryUI" style="margin-left:5px;"> 高级查询 </el-button>
                        <el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="showAdvanceQueryUI" style="margin-left:5px;"> 隐藏 </el-button>
                <el-button type="primary" style="margin-left:5px;" icon="ele-Plus" @click="openAddStall" v-auth="'stall:add'"> 新增 </el-button>
                
              </el-button-group>
            </el-form-item>
            
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card class="full-table" shadow="hover" style="margin-top: 5px">
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
                				row-key="id"
                @sort-change="sortChange"
				border="">
        <el-table-column type="index" label="序号" width="55" align="center"/>
        <el-table-column prop="carNo" label="车位号"  show-overflow-tooltip="" />
        <el-table-column prop="roomId" label="所属小区"  show-overflow-tooltip="">
          <template #default="scope">
            <span>{{scope.row.roomIdCommunityName}}</span>
            
          </template>
          
        </el-table-column>
          <el-table-column prop="carType" label="车位类型"  show-overflow-tooltip="" >
            <template v-slot="scope">
              <el-tag v-if="scope.row.carType==1">地面</el-tag>
              <el-tag v-if="scope.row.carType==2" type="success">地库</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="operation" label="运营模式"  show-overflow-tooltip="" >
            <template v-slot="scope">
              <el-tag v-if="scope.row.operation==1" type="warning">销售</el-tag>
              <el-tag v-if="scope.row.operation==2" type="danger">租赁</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="创建时间"  show-overflow-tooltip=""  sortable/>
         

          <!-- <el-table-column label="用户电话" prop="occupantPhone"></el-table-column> -->
        <el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('stall:update') || auth('stall:delete')">
          <template #default="scope">
          <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditStall(scope.row)" v-auth="'stall:update'"> 编辑 </el-button> 
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delStall(scope.row)" v-auth="'stall:delete'"> 删除 </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    </el-tab-pane>
    

    <el-pagination
      v-model:currentPage="tableParams.page"
      v-model:page-size="tableParams.pageSize"
      :total="tableParams.total"
      :page-sizes="[10, 20, 50, 100, 200, 500]"
      size="small"
      background=""
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      layout="total, sizes, prev, pager, next, jumper"
      prev-text="上一页"
      next-text="下一页"
/>
    <printDialog
      ref="printDialogRef"
      :title="printStallTitle"
      @reloadTable="handleQuery" />
    <editDialog
      ref="editDialogRef"
      :title="editStallTitle"
      @reloadTable="handleQuery"
    />
  </div>

 
    </el-tabs>
  </div>
   
</template>

<script lang="ts" setup="" name="stall">
  import { onMounted, ref } from "vue";
  import { ElMessageBox, ElMessage, SCOPE } from "element-plus";
  import { auth } from '/@/utils/authFunction';
  import { getAPI } from '/@/utils/axios-utils';

  import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
  import { getDictLabelByVal as dv } from '/@/utils/dict-utils';
  import { formatDate } from '/@/utils/formatTime';


  import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
  import editDialog from '/@/views/parking/stall/component/editDialog.vue'
  import { pageStall, deleteStall } from '/@/api/parking/stall';
import { Calendar } from '@element-plus/icons-vue'
  const showAdvanceQueryUI = ref(false);
  const printDialogRef = ref();
  const editDialogRef = ref();
  const loading = ref(false);
  const tableData = ref<any>([]);
  const queryParams = ref<any>({});
  const tableParams = ref({
    page: 1,
    pageSize: 10,
    field: 'createTime', // 默认的排序字段
    order: 'descending', // 排序方向
    descstr: 'descending', // 降序排序的关键字符
    total: 0 as any,
  });
  const printStallTitle = ref("");
  const editStallTitle = ref("");

  // 改变高级查询的控件显示状态
  const changeAdvanceQueryUI = () => {
    showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
  }

  // 查询操作
  const handleQuery = async () => {
    loading.value = true;
    var res = await pageStall(Object.assign(queryParams.value, tableParams.value));
    tableData.value = res.data.result?.items ?? [];
    tableParams.value.total = res.data.result?.total;
    loading.value = false;
  };

  const bb = ()=>{

  }

  // 列排序
  const sortChange = async (column: any) => {
	tableParams.value.field = column.prop;
	tableParams.value.order = column.order;
	await handleQuery();
  };

  // 打开新增页面
  const openAddStall = () => {
    localStorage.setItem("editStallTitle","添加车位表")
    editStallTitle.value = '添加车位表';
    editDialogRef.value.openDialog({});
  };

  // 打开打印页面
  const openPrintStall = async (row: any) => {
    localStorage.setItem("editStallTitle","打印车位表")
    printStallTitle.value = '打印车位表';
  }
  
  // 打开编辑页面
  const openEditStall = (row: any) => {
    localStorage.setItem("editStallTitle","编辑车位表")
    editStallTitle.value = '编辑车位表';
    editDialogRef.value.openDialog(row);
  };

  // 删除
  const delStall = (row: any) => {
    ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
  .then(async () => {
    await deleteStall(row);
    handleQuery();
    ElMessage.success("删除成功");
  })
  .catch(() => {});
  };

  //改变页面容量
  const handleSizeChange = (val: number) => {
    tableParams.value.pageSize = val;
    handleQuery();
  };

  //改变页码序号
  const handleCurrentChange = (val: number) => {
    tableParams.value.page = val;
    handleQuery();
  };

  handleQuery();
</script>
<style scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>

<style>
.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #672e2e;
  font-size: 32px;
  font-weight: 600;
  
}
.demo-tabs .custom-tabs-label .el-icon {
  vertical-align: middle;
}
.demo-tabs .custom-tabs-label span {
  vertical-align: middle;
  margin-left: 4px;
}
</style>